// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:ffi' as ffi;

import 'package:meta/meta.dart' show internal;

import 'arkarray.dart' as array;
import 'arkobject.dart' hide ArkObject;
import 'arkreference.dart';
import 'lang/arkstring.dart' as lang;
import 'third_party/generated_bindings.dart' hide napi_value;
import 'types.dart';

@internal
class MethodInvocation {
  final ffi.Pointer<ffi.Void> result;
  final lang.ArkString methodDescriptor;
  final array.ArkArray? args;

  MethodInvocation._(this.result, this.methodDescriptor, this.args);

  factory MethodInvocation.fromAddresses(
    int resultAddress,
    int descriptorAddress,
    int argsAddress,
  ) {
    return MethodInvocation._(
      ffi.Pointer<ffi.Void>.fromAddress(resultAddress),
      lang.ArkString('method_descriptor'), // TODO: implement fromReference
      argsAddress == 0
          ? null
          : array.ArkArray(0), // TODO: implement fromReference
    );
  }

  factory MethodInvocation.fromMessage(List<dynamic> message) {
    return MethodInvocation.fromAddresses(
      message[0] as int,
      message[1] as int,
      message[2] as int,
    );
  }
}
